Option Strict On
Imports Excel = Microsoft.Office.Interop.Excel

Public Class RowSpacer
    Implements ITemplateSpacer

    Private rowCount As Int32
    Private location As Excel.Range

    Public Sub New(ByVal tableName As String, ByRef dSet As DataSet, ByRef range As Excel.Range, ByVal mulIndex As Decimal)
        If (dSet Is Nothing) Then
            Throw New ArgumentException("DataSet object was not supplyed!")
        End If

        Dim table As DataTable = dSet.Tables(tableName)
        If (table Is Nothing) Then
            Throw New ArgumentException( _
                String.Format("There are no Table with name: '{0}' in supplyed DataSet object!", tableName))
        End If
        Me.rowCount = CType(table.Rows.Count * mulIndex, Int32) - 3
        Me.location = range
    End Sub

    Public Sub DeploySpacer() Implements ITemplateSpacer.DeploySpacer
        Dim i As Int32
        Dim row As Excel.Range = location.Worksheet.Range(location.Row.ToString & ":" & location.Row.ToString)
        For i = 0 To rowCount - 1
            row.Insert(Excel.XlDirection.xlDown, False)
        Next
        Me._IsDeployed = True
    End Sub

    Private _IsDeployed As Boolean = False
    Public ReadOnly Property IsDeployed() As Boolean Implements ITemplateSpacer.IsDeployed
        Get
            Return Me._IsDeployed
        End Get
    End Property
End Class
